﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Config;
using WebTriple7.Class;
using WebTriple7.Constants;

namespace WebTriple7.Pages
{
    public partial class RedirectPage : System.Web.UI.Page
    {
        private const string PLAY_ON = "playOn";

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var value = Request.QueryString[PLAY_ON];

                string urlRedirect = "http://nguyenxi.vn";


                if (string.IsNullOrEmpty(value))
                {
                    value = "defalut";
                }

                switch (value)
                {
                    case "go-vn":
                        GoVnSession.ResultCheck goResultCheck = GoVnSession.CheckSession();
                        if (goResultCheck == GoVnSession.ResultCheck.GO_ACCESS_TOKEN_NULL)
                            urlRedirect = string.Format(Config.Global.Settings.GET_CODE_URL, Config.Global.Settings.CLIENT_ID);
                        else
                            urlRedirect = ConfigurationManager.AppSettings[ConfigKey.PLAY_ON_GO_VN];

                        break;
                    case "gosu-vn":
                        urlRedirect = string.Format(Config.Global.Settings.GOSU_GET_CODE_URL, Config.Global.Settings.GOSU_CLIENT_ID);
                        break;

                    default:
                        urlRedirect = ConfigurationManager.AppSettings[ConfigKey.PLAY_ON_DEFAULT];
                        break;
                }                
                Response.Redirect(urlRedirect);
            }
            catch (Exception ex)
            {
                //???
            }
        }
    }
}